package com.hd.day03;

import java.lang.reflect.Array;
import java.util.Arrays;

public class LearnArray02 {
    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5, 6};

        System.out.println("洗牌之前" + Arrays.toString(arr));

        // 第一种
        //int first = arr[arr.length - 1];
        //arr[arr.length - 1] = arr[0];
        //arr[0] = first;


        // 第二种
        //arr[0] = arr[0] + arr[arr.length - 1];
        //arr[arr.length - 1] = arr[0] - arr[arr.length - 1];
        //arr[0] = arr[0] - arr[arr.length - 1];

        // 第三种
        //arr[0] = arr[0] ^ arr[arr.length - 1];
        //arr[arr.length - 1] = arr[0] ^ arr[arr.length - 1];
        //arr[0] = arr[0] ^ arr[arr.length - 1];


        for (int i = 0; i < 8; i++) {
            int a = (int) (Math.random() * arr.length);
            int b = (int) (Math.random() * arr.length);


            int first = arr[a];
            arr[a] = arr[b];
            arr[b] = first;
        }

        //int a = (int) (Math.random() * arr.length);
        //int b = (int) (Math.random() * arr.length);
        //System.out.println(a);
        //System.out.println(b);
        //System.out.println(Math.random());


        System.out.println("洗牌之后" + Arrays.toString(arr));

    }
}
